package com.xx.bysj.controller;

import com.xx.bysj.aop.LogAop;
import com.xx.bysj.aop.LogConsts;
import com.xx.bysj.dto.HnMenu;
import com.xx.bysj.dto.HnOrder;
import com.xx.bysj.dto.HnOrderInfo;
import com.xx.bysj.service.OrderService;
import com.xx.bysj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/add")
    @ResponseBody
    @LogAop(actionName = "新增订单",actionType = LogConsts.ACTION_ADD)
    public Result addMenu(HnOrderInfo order, Authentication authentication, HttpServletRequest request,@RequestParam("imgList") List<String> imgList){
        return orderService.addOrder(order,authentication,request,imgList);
    }

    /**
     * mongodb上传图片
     * @param file
     * @param request
     * @param authentication
     * @return
     */
    @RequestMapping("/uploadMongoDb")
    @ResponseBody
    @LogAop(actionName = "MongoDb头像上传",actionType = LogConsts.ACTION_UPLOAD)
    public Result uploadMongoDb(@RequestParam("file") MultipartFile[] file, HttpServletRequest request, Authentication authentication){
        return orderService.uploadMongoDb(file,request,authentication);
    }

    /**
     * 获取图片
     */
    @GetMapping(value = "/mongoDbShow/{id}", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_PNG_VALUE})
    @LogAop(actionName = "MongoDb查看图片",actionType = LogConsts.ACTION_QUERY)
    public void mongoDbShow(@PathVariable("id") String id, HttpServletResponse response) {
        orderService.mongoDbShow(id,response);
    }

    @RequestMapping("/query")
    @ResponseBody
    @LogAop(actionName = "新增订单",actionType = LogConsts.ACTION_ADD)
    public Result query(HnOrder order,Authentication authentication,
                        @RequestParam int page,
                        @RequestParam int limit){
        return orderService.query(order,authentication,page,limit);
    }

    @RequestMapping("/cancel")
    @ResponseBody
    @LogAop(actionName = "新增订单",actionType = LogConsts.ACTION_ADD)
    public Result cancel(String orderNum,Authentication authentication){
        return orderService.cancel(orderNum,authentication);
    }

    @RequestMapping("/edits")
    @ResponseBody
    @LogAop(actionName = "修改订单",actionType = LogConsts.ACTION_ADD)
    public Result edit(HnOrderInfo order, Authentication authentication, HttpServletRequest request,@RequestParam("imgList") List<String> imgList){
        return orderService.edit(order,authentication,imgList);
    }

    @RequestMapping("/queryReceive")
    @ResponseBody
    @LogAop(actionName = "新增订单",actionType = LogConsts.ACTION_ADD)
    public Result queryReceive(HnOrder order,Authentication authentication,
                        @RequestParam int page,
                        @RequestParam int limit){
        return orderService.queryReceive(order,authentication,page,limit);
    }

    @RequestMapping("/finish")
    @ResponseBody
    @LogAop(actionName = "新增订单",actionType = LogConsts.ACTION_ADD)
    public Result finish(String orderNum,Authentication authentication){
        return orderService.finish(orderNum,authentication);
    }
}
